package com.yunfeng.learning.ribbon.customer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@SpringBootApplication
@RestController
@EnableEurekaClient
public class GreetingServiceApplication {
    private  String[] greetingWords = new String [] {"Hi there", "Greetings", "Salutations"};

	public static void main(String[] args) {

	    SpringApplication.run(GreetingServiceApplication.class, args);
	}

	@RequestMapping("/greetingWord")
	public String greetingWord() {
	    if(new Random().nextInt(100) < 50)
            throw new RuntimeException("Random lower than 50");
	    return greetingWords[new Random().nextInt(greetingWords.length)];
 	}

}
